﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Perform
{
    public partial class frmFlowerSelect : Form
    {
        public frmFlowerSelect()
        {
            InitializeComponent();
        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void frmFlowerSelect_Load(object sender, EventArgs e)
        {
            string sql1 = "select fname from flower";
            SqlDataReader sdr = Dal.DataHelper.ExecuteReader(sql1);
            while (sdr.Read())
            {
                cmbfname.Items.Add(sdr["fname"].ToString());
            }
        }

        private void cmbfname_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sql = "select fid as 鲜花编号,fname as 鲜花名称,flauguage as 花语,fprimecost as 进货价,fsalecost as 销售价,iid as 库存编号 from flower where fname='" + cmbfname.Text.Trim() + "'";
            SqlDataReader sdr = Dal.DataHelper.ExecuteReader(sql);
            while (sdr.Read())
            { tbfid.Text = sdr["鲜花编号"].ToString(); }
            string sql1 = "select fid as 鲜花编号,fname as 鲜花名称,flauguage as 花语,fprimecost as 进货价,fsalecost as 销售价,iid as 库存编号 from flower where fname='" + cmbfname.Text.Trim() + "'";
            dataGridView1.DataSource = Dal.DataHelper.getDataSet(sql1,"鲜花表").Tables["鲜花表"];
        }

        private void btnlookup_Click(object sender, EventArgs e)
        {
            string sql = "select fid as 鲜花编号,fname as 鲜花名称,flauguage as 花语,fprimecost as 进货价,fsalecost as 销售价,iid as 库存编号 from flower";
            dataGridView1.DataSource = Dal.DataHelper.getDataSet(sql,"鲜花表").Tables["鲜花表"];
        }

        private void btndel_Click(object sender, EventArgs e)
        {
            string sql1 = "delete from flower where fid='" + tbfid.Text.Trim() + "'";
            if (Dal.DataHelper.sqlExecuteNonQuery(sql1) > 0)
            {
                MessageBox.Show("删除鲜花信息成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                MessageBox.Show("删除鲜花信息失败！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
    }
}
